import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 40

        ColumnLayout{
            Layout.alignment: Qt.AlignTop

            VisionLocationViewer{
                calibrationName: "CaliGlassUplookCalibration"
                visionLocationName: "CaliGlassUplookLocation"
            }

//            ConfigRow{
//                configModel: bhConfig
//                configName: "corCaliStartPos"
//                Component.onCompleted: {
//                    init(ConfigElementType.Double)
//                }
//            }
            ConfigRow{
                configModel: bhConfig
                configName: "corCaliStepCount"
                Component.onCompleted: {
                    init(ConfigElementType.Int)
                }
            }
            ConfigRow{
                configModel: bhConfig
                configName: "corCaliStepSize"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            ConfigRow{
                enabled: false
                configModel: bhConfig
                configName: "bhToLTCameraOffsetX"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            ConfigRow{
                enabled: false
                configModel: bhConfig
                configName: "bhToLTCameraOffsetY"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            Button{
                text: qsTr("CalibrateBHToLTCameraOffset")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "calibrateBHToLTCameraOffset")
                }
            }
            Button{
                text: qsTr("MoveToPickLTCaliGlass")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "moveToPickLTCaliGlass")
                }
            }
        }

        ColumnLayout{
            Layout.alignment: Qt.AlignTop

            ConfigRow{
                configModel: bhConfig
                configName: "bhCorToUplookCameraOffsetX"
                Component.onCompleted: {
                    autoInit()
                }
            }
            ConfigRow{
                configModel: bhConfig
                configName: "bhCorToUplookCameraOffsetY"
                Component.onCompleted: {
                    autoInit()
                }
            }
            Button{
                text: qsTr("MoveToCalibrateCor")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "moveToCalibrateCor")
                }
            }

            GroupBox{
                title: qsTr("LensTrayCameraToUplookCameraOffset")
                ColumnLayout{
                    RowLayout{
                        ConfigRow{
                            configModel: ltCameraToUplookCameraOffset
                            configName: "x"
                            Component.onCompleted: {
                                init(ConfigElementType.Double)
                            }
                        }
                        ConfigRow{
                            configModel: ltCameraToUplookCameraOffset
                            configName: "y"
                            Component.onCompleted: {
                                init(ConfigElementType.Double)
                            }
                        }
                        ConfigRow{
                            configModel: ltCameraToUplookCameraOffset
                            configName: "theta"
                            Component.onCompleted: {
                                init(ConfigElementType.Double)
                            }
                        }
                    }
                    Button{
                        text: qsTr("CalibrateLTCameraToUplookCameraOffset")
                        onClicked: {
                            tem.runSingleCmd(bonderHead, "calibrateLTCameraToUplookCameraOffset")
                        }
                    }
                }
            }

            ConfigRow{
                configModel: bhConfig
                configName: "ltCameraCenterXShift"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            Button{
                text: qsTr("PlaceCaliGlassToLTCameraCenter")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "placeCaliGlassToLTCameraCenter")
                }
            }
        }
    }
}
